package br.com.ravi.crm.core.taglib;

import java.util.List;

import br.com.ravi.utils.DateUtils;
import br.com.ravi.utils.DateUtils.WeekOfYear;

public class ScheduleHtmlRenderer {
	public static CharSequence renderHTML(List<DateUtils.WeekOfYear> weeksOfYear, ScheduleTagLibrary.Options options) {
		StringBuilder html = new StringBuilder();
		html.append(String.format("	<div id=\"_schedule\" class=\"schedule\" style=\"width:%dpx;height:%dpx;\">", options.width, options.height));
		html.append(String.format("		%s", renderWeeksOfYear(weeksOfYear)));
		html.append("				</div>");
		
		return html;
	}

	private static CharSequence renderWeeksOfYear(List<WeekOfYear> weeksOfYear) {
		StringBuilder html = new StringBuilder();
		
		for(int ix=0;ix<=4;ix++) {
			WeekOfYear weekOfYear = weeksOfYear.get(ix);
			List<Integer> daysOfWeek = weekOfYear.getDaysOfWeek();
			
			html.append(String.format("<div id=\"_scheduleRow%d\" class=\"schedule-row\">", ix));
			
			for(int jx=0;jx<=6;jx++) {
				Integer currentDay = daysOfWeek.get(jx);
				html.append(String.format("<div id=\"_scheduleCol%dRow%d\" class=\"schedule-cell\">", jx, ix));
				html.append(currentDay);
				html.append("</div>");
			}
			
			html.append("</div>");
		}
		
		return html;
	}
}
